package dk.jagtogjaeger.domain;

import java.util.ArrayList;
import java.util.Collection;

import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;

public class TrackerDogDBAdapter {

	/*
	 * fetchAllTrackerDogs() retrieves all the tracker dogs in the DB.
	 * And return them as a collection.
	 */
	public Collection<TrackerDog> fetchAllTrackerDogs(SQLiteDatabase db) {
		// Query for trackerDogs.
		Cursor rs = db.query("trackerdog", new String[] { "tdid", "name",
				"address", "postalcode", "city", "municipality", "region",
				"phone1", "phone2", "GPSX", "GPSY" }, null, null, null, null,
				null);
		// Return Array being created.
		Collection<TrackerDog> res = new ArrayList<TrackerDog>();
		// While loop to make all the cursors into objects.
		while (rs.moveToNext()) {
			res.add(new TrackerDog(rs.getInt(0), rs.getString(1), rs
					.getString(2), rs.getInt(3), rs.getString(4), rs
					.getString(5), rs.getInt(6), rs.getInt(7), rs.getInt(8), rs
					.getDouble(9), rs.getDouble(10)));
		}
		rs.close();
		return res;
	}
}
